package service;
import java.util.List;

import util.TestConnection;
import model.User;
import dao.DaoProxy;
import dao.IUserDAO;
public class UserService implements IUserService{
	DaoProxy dao1=null;
	public UserService() throws Exception{
		super();
		dao1=new DaoProxy();
	}
	public boolean insertUser(User user) throws Exception  {
		if(dao1.findByName(user.getname())==null){
			dao1=new DaoProxy();
			return dao1.insertUser(user);
			}
		else 
			return false;
	}
	public boolean updateUser(User user ) throws Exception{
		return dao1.updateUser(user);
	}

	public boolean deleteUser(User user)throws Exception {
		return dao1.deleteUser(user);
	}
	public List<User> findAll() throws Exception {
		return dao1.findAll();
	}
	public User findByName(String name) throws Exception {
		return dao1.findByName(name);
	}
	public boolean checkName(String name,String password) throws Exception{
		boolean test=false;
		User user=null;
		if(dao1.IsName(name))
			test=false;//用户名不存在
		else{
			dao1=new DaoProxy();
			user=dao1.findByName(name);
			if(user.getpassword().equals(password))
				test=true;
		}
		return test;
	}
	public boolean IsName(String name) throws Exception {
		return dao1.IsName(name);
	}
	public User findById(int Id) throws Exception {
	   return dao1.findById(Id);
	}
}

